<template>
  <div class="judge-button-container">
    <el-button
      type="primary"
      size="small"
      :color="colorManager.getColor('__accept_button_color')"
      @click="submitContributeJudgeByButton(props.item, 20102)"
      >通过审核</el-button
    >
    <el-button
      type="primary"
      size="small"
      :color="colorManager.getColor('__reject_button_color')"
      @click="submitContributeJudgeByButton(props.item, 20103)"
      >拒绝通过</el-button
    >
  </div>
</template>

<script setup>
import { colorManager } from "@/assets/scss/colors-util.js";
import { ElMessageBox } from "element-plus";
import { submitContributeJudgeForm } from "@/api/content/contributejudge/contributejudge.js";
import { AbstractComfirmBox } from "@/utils/MessageUtils.js";
const props = defineProps({
  item: {
    default: null,
  },
});
const emit = defineEmits("refresh"); // 执行的刷新操作

// ## 审核内容
/**
 * item是被审核的审核项实体
 * result是审核的结果
 */
const submitContributeJudgeByButton = async (item, judgeResult) => {
  if (item === null) {
    ElMessageBox({ message: "系统错误", type: "error" });
    return;
  }
  // 提供删除确认
  const isConfirm = await AbstractComfirmBox("-审核-");
  if (!isConfirm) {
    return;
  }

  var contributeJudgeSubmit = {};
  contributeJudgeSubmit.contributeJudgeId = item.id;
  contributeJudgeSubmit.judgeResult = judgeResult;
  // 提交
  var res = await submitContributeJudgeForm(contributeJudgeSubmit);

  if (res.code === 1) {
    ElMessageBox({ message: "提交成功", type: "success" });
    emit("refresh");
  } else {
    ElMessageBox({ message: "提交失败", type: "error" });
  }
};
</script>

<style lang="scss">
.judge-button-container {
  display: flex;
  flex-direction: column;
  align-items: center; /* 可选，用于居中对齐 */
  .el-button {
    margin: 10px;
  }
}
</style>
